﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB.YJKControls;
using HYFamilyLibDataManager;

namespace YJKArch.DoorWinModule
{
	internal partial class DlgDoorWinTagInsert : System.Windows.Forms.Form
	{
		public DlgDoorWinTagInsert(UIApplication uiApp)
		{
			try
			{
				this.m_application = uiApp;
				this.m_document = uiApp.ActiveUIDocument.Document;
				this.fInfo = Assist.FileUtil.GetTempDataFile();
				this.archDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Architecture, this.m_application.Application.VersionNumber);
				this.sysDB = FamilyLibDatabase.GetSqliteDB(SubjectType.System, this.m_application.Application.VersionNumber);
				this.InitializeComponent();
				this.InitType();
				this.InitSelect();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "盈建科提示");
			}
		}

		private void InitSelect()
		{
			if (Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "是否选择集编号") == "是")
			{
				this.rbSelection.Checked = true;
				if (Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "类型过滤") == "是")
				{
					this.cbByType.Checked = true;
					return;
				}
			}
			else
			{
				this.rbSingle.Checked = true;
			}
		}

		private void InitType()
		{
			if (Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "是否窗编号") == "是")
			{
				this.rbtWin.Checked = true;
				this.cbxSymbol.Items.Clear();
				foreach (DbCategory dbCategory in this.sysDB.CategoryTable.GetAll())
				{
					if (dbCategory.Name == "窗标记")
					{
						foreach (DbFamily item in dbCategory.GetAllFamilies(false, CheckType.All))
						{
							this.cbxSymbol.Items.Add(item);
						}
					}
				}
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "窗标记样式");
				IEnumerator enumerator3 = this.cbxSymbol.Items.GetEnumerator();
				{
					while (enumerator3.MoveNext())
					{
						object obj = enumerator3.Current;
						if (obj.ToString() == dataFromTempFile)
						{
							this.cbxSymbol.SelectedItem = obj;
							break;
						}
						if (this.cbxSymbol.Items.Count > 0)
						{
							this.cbxSymbol.SelectedIndex = 0;
						}
					}
					return;
				}
			}
			this.rbtDoor.Checked = true;
			foreach (DbCategory dbCategory2 in this.sysDB.CategoryTable.GetAll())
			{
				if (dbCategory2.Name == "门标记")
				{
					foreach (DbFamily item2 in dbCategory2.GetAllFamilies(false, CheckType.All))
					{
						this.cbxSymbol.Items.Add(item2);
					}
				}
			}
			string dataFromTempFile2 = Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "门标记样式");
			foreach (object obj2 in this.cbxSymbol.Items)
			{
				if (obj2.ToString() == dataFromTempFile2)
				{
					this.cbxSymbol.SelectedItem = obj2;
					break;
				}
				if (this.cbxSymbol.Items.Count > 0)
				{
					this.cbxSymbol.SelectedIndex = 0;
				}
			}
		}

		private void rbSingle_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbSingle.Checked)
			{
				this.cbByType.Checked = false;
				this.cbByType.Enabled = false;
			}
		}

		private void rbSelection_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbSelection.Checked)
			{
				this.cbByType.Checked = false;
				this.cbByType.Enabled = true;
			}
		}

		private void tbxTag_MouseClick(object sender, MouseEventArgs e)
		{
		}

		private void tbxTag_Leave(object sender, EventArgs e)
		{
		}

		private void btnOK(object sender, EventArgs e)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			if (this.rbtDoor.Checked)
			{
				dictionary.Add("是否窗编号", "否");
				dictionary.Add("门标记样式", this.cbxSymbol.Text);
			}
			else
			{
				dictionary.Add("是否窗编号", "是");
				dictionary.Add("窗标记样式", this.cbxSymbol.Text);
			}
			if (this.rbSingle.Checked)
			{
				dictionary.Add("是否选择集编号", "否");
			}
			else
			{
				dictionary.Add("是否选择集编号", "是");
			}
			if (this.cbByType.Checked)
			{
				dictionary.Add("类型过滤", "是");
			}
			else
			{
				dictionary.Add("类型过滤", "否");
			}
			Assist.FileUtil.WriteTempData(this.fInfo.FullName, "门窗编号", ConfigData.DoorWinTagData, dictionary);
		}

		private void rbtDoor_CheckedChanged(object sender, EventArgs e)
		{
			this.cbxSymbol.Items.Clear();
			if (this.rbtDoor.Checked)
			{
				foreach (DbFamily item in this.sysDB.CategoryTable["建筑标记"]["门标记"].GetAllFamilies(false, CheckType.All))
				{
					this.cbxSymbol.Items.Add(item);
				}
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "窗标记样式");
				foreach (object obj in this.cbxSymbol.Items)
				{
					if (obj.ToString() == dataFromTempFile)
					{
						this.cbxSymbol.SelectedItem = obj;
						break;
					}
					if (this.cbxSymbol.Items.Count > 0)
					{
						this.cbxSymbol.SelectedIndex = 0;
					}
				}
			}
		}

		private void rbtWin_CheckedChanged(object sender, EventArgs e)
		{
			this.cbxSymbol.Items.Clear();
			if (this.rbtWin.Checked)
			{
				foreach (DbFamily item in this.sysDB.CategoryTable["建筑标记"]["窗标记"].GetAllFamilies(false, CheckType.All))
				{
					this.cbxSymbol.Items.Add(item);
				}
				string dataFromTempFile = Assist.FileUtil.GetDataFromTempFile(this.fInfo.FullName, "门窗编号", "窗标记样式");
				foreach (object obj in this.cbxSymbol.Items)
				{
					if (obj.ToString() == dataFromTempFile)
					{
						this.cbxSymbol.SelectedItem = obj;
						break;
					}
					if (this.cbxSymbol.Items.Count > 0)
					{
						this.cbxSymbol.SelectedIndex = 0;
					}
				}
			}
		}

		private UIApplication m_application;

		private Autodesk.Revit.DB.Document m_document;

		private FamilyLibDatabase archDB;

		public FamilyLibDatabase sysDB;

		private FileInfo fInfo;
	}
}
